package com.gadgets.busi.dataanalysis.registry.task;

import com.gadgets.busi.bm02.service.IMaterialAnalysisService;
import com.gadgets.framework.common.util.StringUtils;
import com.gadgets.framework.thread.task.AbstractRunnable;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2020-12-01
 *   最小权算法
 */
public class DataAnaylsisMainRunnable extends AbstractRunnable {

    private IMaterialAnalysisService analysisService;

    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see Thread#run()
     */
    @SuppressWarnings("BusyWait")
    @Override
    public void run() {
        while (true) {
            logger.info("合成表最小权任务启动");
            try {
                analysisService.analysisBuildWeight();
            } catch (Exception exception) {
                logger.error(StringUtils.formatExceptionStack(exception));
            }
            logger.info("合成表最小权任务结束");
            try {
                Thread.sleep(2*60*1000);
            } catch (InterruptedException e) {
                logger.error("最小权计算线程休眠失败");
                logger.error(StringUtils.formatExceptionStack(e));
            }
        }
    }

    public IMaterialAnalysisService getAnalysisService() {
        return analysisService;
    }

    public void setAnalysisService(IMaterialAnalysisService analysisService) {
        this.analysisService = analysisService;
    }
}
